home *** CD-ROM | disk | FTP | other *** search
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class FIXED_ARRAY[E]
- --
- -- The `lower' bound is frozen. Thus, FIXED_ARRAY should
- -- run a little bit faster than ARRAY.
- --
-
- inherit COLLECTION[E];
-
- creation {ANY}
- make, resize
-
- feature
-
- lower: INTEGER is 0;
- -- Lower index bound.
-
- upper: INTEGER;
- -- Upper index bound.
-
- feature {NONE}
-
- storage: POINTER;
- -- Internal access to storage location.
- -- Corresoponding C type is computed according
- -- to generic type E.
-
- feature -- Creation and Modification :
-
- make(size: INTEGER) is
- require
- size >= 0
- do
- if storage /= Void then
- c_inline_c("free(C->_storage);");
- end;
- c_inline_c("C->_storage=malloc(((size_t)%
- %sizeof(*(C->_storage))*a1));");
- upper := size - 1;
- clear_all;
- ensure
- count = size;
- all_cleared
- end;
-
- feature -- Accessing :
-
- infix "@", item(index: INTEGER): E is
- do
- c_inline_c("R=(C->_storage)[a1];")
- end;
-
- feature -- Modification :
-
- put(element: E; index: INTEGER) is
- do
- c_inline_c("(C->_storage)[a2]=a1;");
- end;
-
- clear is
- -- Empty the array, discard all items.
- do
- upper := -1;
- if storage /= Void then
- c_inline_c("free(C->_storage);");
- storage := Void;
- end;
- end;
-
- copy(other: like Current) is
- -- Copy `other' onto Current.
- local
- i: INTEGER;
- do
- if upper /= other.upper then
- make(other.upper);
- end;
- from
- i := upper;
- until
- i = lower
- loop
- put(other.item(i),i);
- i := i - 1;
- end;
- end;
-
- invariant
-
- upper >= lower implies storage /= Void;
-
- end -- FIXED_ARRAY[E]
-